var express = require('express')
var { graphql } = require('graphql')
var router = express.Router()

var schema = require('../schema/schema')

router.get('/movies', async function(req, res, next) {
  const sql = `
    {
      hello,
      movie {
        title
      },
      movies {
        id,
        title,
        genres,
        rating
      }
    }
  `
  let result = await graphql(schema, sql)
  res.json(result)
})

router.get('/movie', async function(req, res, next) {
  let id = req.query.id
  const sql = `
    {
      movie(id: ${id}) {
        title
      },
    }
  `
  let result = await graphql(schema, sql)
  res.json(result)
})

module.exports = router
